home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / demo / pwrtcp11.exe / TELNETEX.FR_ / TELNETEX.bin
Text File  |  1995-02-16  |  13KB  |  429 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Telnet Example"
  4.    ClientHeight    =   5820
  5.    ClientLeft      =   972
  6.    ClientTop       =   1428
  7.    ClientWidth     =   7368
  8.    Height          =   6192
  9.    Icon            =   TELNETEX.FRX:0000
  10.    Left            =   924
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5820
  13.    ScaleWidth      =   7368
  14.    Top             =   1104
  15.    Width           =   7464
  16.    Begin PowerTCP_TNT tntConnectFrom 
  17.       Flags           =   0
  18.       Left            =   6300
  19.       LocalDotAddr    =   ""
  20.       OemLicense      =   ""
  21.       RemoteHost      =   ""
  22.       RemotePort      =   23
  23.       Top             =   4500
  24.    End
  25.    Begin PowerTCP_TNT tntConnectTo 
  26.       Flags           =   0
  27.       Left            =   6300
  28.       LocalDotAddr    =   ""
  29.       OemLicense      =   ""
  30.       RemoteHost      =   ""
  31.       RemotePort      =   23
  32.       Top             =   2100
  33.    End
  34.    Begin PowerTCP_TNT tntListen 
  35.       Flags           =   0
  36.       Left            =   1980
  37.       LocalDotAddr    =   ""
  38.       OemLicense      =   ""
  39.       RemoteHost      =   ""
  40.       RemotePort      =   23
  41.       Top             =   300
  42.    End
  43.    Begin CommandButton cmdExit 
  44.       Caption         =   "E&xit"
  45.       Height          =   375
  46.       Left            =   6000
  47.       TabIndex        =   14
  48.       Top             =   120
  49.       Width           =   1215
  50.    End
  51.    Begin Frame Frame3 
  52.       Caption         =   "Connected &From"
  53.       Height          =   1935
  54.       Left            =   120
  55.       TabIndex        =   13
  56.       Top             =   3720
  57.       Width           =   7095
  58.       Begin CommandButton cmdConnectFromClose 
  59.          Caption         =   "Clo&se"
  60.          Enabled         =   0   'False
  61.          Height          =   375
  62.          Left            =   5760
  63.          TabIndex        =   16
  64.          Top             =   1440
  65.          Width           =   1215
  66.       End
  67.       Begin TextBox txtConnectFrom 
  68.          FontBold        =   0   'False
  69.          FontItalic      =   0   'False
  70.          FontName        =   "Fixedsys"
  71.          FontSize        =   10.8
  72.          FontStrikethru  =   0   'False
  73.          FontUnderline   =   0   'False
  74.          Height          =   1455
  75.          Left            =   120
  76.          MultiLine       =   -1  'True
  77.          ScrollBars      =   2  'Vertical
  78.          TabIndex        =   15
  79.          Top             =   360
  80.          Width           =   5175
  81.       End
  82.    End
  83.    Begin Frame Frame2 
  84.       Caption         =   "&Listen"
  85.       Height          =   855
  86.       Left            =   120
  87.       TabIndex        =   0
  88.       Top             =   120
  89.       Width           =   5175
  90.       Begin CommandButton cmdStop 
  91.          Caption         =   "&Stop"
  92.          Height          =   375
  93.          Left            =   3720
  94.          TabIndex        =   4
  95.          Top             =   360
  96.          Width           =   1215
  97.       End
  98.       Begin TextBox txtListenPort 
  99.          Height          =   375
  100.          Left            =   600
  101.          TabIndex        =   2
  102.          Text            =   "23"
  103.          Top             =   360
  104.          Width           =   1215
  105.       End
  106.       Begin CommandButton cmdListen 
  107.          Caption         =   "&Listen"
  108.          Height          =   375
  109.          Left            =   2280
  110.          TabIndex        =   3
  111.          Top             =   360
  112.          Width           =   1215
  113.       End
  114.       Begin Label Label3 
  115.          Caption         =   "&Port:"
  116.          Height          =   375
  117.          Left            =   120
  118.          TabIndex        =   1
  119.          Top             =   360
  120.          Width           =   1215
  121.       End
  122.    End
  123.    Begin Frame Frame1 
  124.       Caption         =   "Connect &To"
  125.       Height          =   2535
  126.       Left            =   120
  127.       TabIndex        =   5
  128.       Top             =   1080
  129.       Width           =   7095
  130.       Begin CommandButton cmdConnectToClose 
  131.          Caption         =   "C&lose"
  132.          Enabled         =   0   'False
  133.          Height          =   375
  134.          Left            =   5760
  135.          TabIndex        =   11
  136.          Top             =   2040
  137.          Width           =   1215
  138.       End
  139.       Begin TextBox txtConnectToPort 
  140.          Height          =   375
  141.          Left            =   5640
  142.          TabIndex        =   9
  143.          Text            =   "23"
  144.          Top             =   240
  145.          Width           =   1335
  146.       End
  147.       Begin TextBox txtConnectToAddress 
  148.          Height          =   375
  149.          Left            =   3240
  150.          TabIndex        =   7
  151.          Text            =   "x.x.x.x"
  152.          Top             =   240
  153.          Width           =   1335
  154.       End
  155.       Begin CommandButton cmdConnect 
  156.          Caption         =   "&Connect"
  157.          Height          =   375
  158.          Left            =   5760
  159.          TabIndex        =   10
  160.          Top             =   1560
  161.          Width           =   1215
  162.       End
  163.       Begin TextBox txtConnectTo 
  164.          FontBold        =   0   'False
  165.          FontItalic      =   0   'False
  166.          FontName        =   "Fixedsys"
  167.          FontSize        =   10.8
  168.          FontStrikethru  =   0   'False
  169.          FontUnderline   =   0   'False
  170.          Height          =   1455
  171.          Left            =   120
  172.          MultiLine       =   -1  'True
  173.          ScrollBars      =   2  'Vertical
  174.          TabIndex        =   12
  175.          Top             =   960
  176.          Width           =   5175
  177.       End
  178.       Begin Label Label2 
  179.          Caption         =   "&Port:"
  180.          Height          =   495
  181.          Left            =   5040
  182.          TabIndex        =   8
  183.          Top             =   240
  184.          Width           =   1215
  185.       End
  186.       Begin Label Label1 
  187.          Caption         =   "&Address:"
  188.          Height          =   495
  189.          Left            =   2280
  190.          TabIndex        =   6
  191.          Top             =   240
  192.          Width           =   1215
  193.       End
  194.    End
  195. End
  196.  
  197. ' IMPORTANT: We MUST use the API MessageBox function
  198. ' instead of the VB MsgBox function. See the PowerTCP
  199. ' README for more information.
  200. Declare Function MessageBox Lib "User" (ByVal hWnd As Integer, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Integer) As Integer
  201.  
  202. Sub cmdConnect_Click ()
  203.     ' Set the properties of the remote computer
  204.     tntConnectTo.RemoteHost = txtConnectToAddress.Text
  205.     tntConnectTo.RemotePort = Val(txtConnectToPort.Text)
  206.  
  207.     ' Make the connection
  208.     tntConnectTo.Action = CONNECT
  209. End Sub
  210.  
  211. Sub cmdConnectFromClose_Click ()
  212.     tntConnectFrom.Action = CLOSECOMM
  213. End Sub
  214.  
  215. Sub cmdConnectToClose_Click ()
  216.     tntConnectTo.Action = CLOSECOMM
  217. End Sub
  218.  
  219. Sub cmdExit_Click ()
  220.     tntConnectTo.Action = ABORTCOMM
  221.     tntListen.Action = ABORTCOMM
  222.     tntConnectFrom.Action = ABORTCOMM
  223.     End
  224. End Sub
  225.  
  226. Sub cmdListen_Click ()
  227.     ' Set the mode of tntListen to Listen
  228.     tntListen.LocalPort = Val(txtListenPort.Text)
  229.     tntListen.Action = LISTEN
  230.  
  231.     ' Make the "Stop" button enabled
  232.     cmdStop.Enabled = True
  233. End Sub
  234.  
  235. Sub cmdStop_Click ()
  236.     tntListen.Action = CLOSECOMM
  237. End Sub
  238.  
  239. Sub Form_Unload (Cancel As Integer)
  240.     End
  241. End Sub
  242.  
  243. Sub tntConnectFrom_Cmd (Cmd As Integer, TelnetOption As Integer, SubOption As String)
  244.     ' When we sent a suboption, it must be 6 bytes long
  245.     Dim MySubOption As String * 6
  246.     
  247.     Select Case Cmd
  248.     Case DO_CMD
  249.         If TelnetOption = TERMINAL_TYPE Then
  250.             ' We will support this option
  251.             tntConnectFrom.WillOption = TERMINAL_TYPE
  252.         Else
  253.             ' We don't support any others
  254.             tntConnectFrom.WontOption = TelnetOption
  255.         End If
  256.  
  257.     Case DONT_CMD
  258.         tntConnectFrom.WontOption = TelnetOption
  259.  
  260.     Case SB_CMD
  261.         ' We support the TTY terminal type
  262.         If TelnetOption = TERMINAL_TYPE Then
  263.             MySubOption = Chr$(0) & "tty"
  264.             tntConnectFrom.SubOption = MySubOption
  265.             tntConnectFrom.DoSubOption = TERMINAL_TYPE
  266.         End If
  267.  
  268.     Case WILL_CMD
  269.         If TelnetOption = SUPPRESS_GO_AHEAD Then
  270.             ' We will support this option
  271.             tntConnectFrom.DoOption = SUPPRESS_GO_AHEAD
  272.         Else
  273.             ' We don't support any others
  274.             tntConnectFrom.DontOption = TelnetOption
  275.         End If
  276.  
  277.     Case WONT_CMD
  278.         ' tntConnectFrom.DontOption = TelnetOption
  279.     End Select
  280. End Sub
  281.  
  282. Sub tntConnectFrom_Connect ()
  283.     cmdConnectFromClose.Enabled = True
  284. End Sub
  285.  
  286. Sub tntConnectFrom_Exception (ErrorCode As Integer, ErrorDesc As String)
  287.     If ErrorCode = PT_CLOSED Or ErrorCode = PT_ABORTED Then
  288.         suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
  289.         cmdConnectFromClose.Enabled = False
  290.     Else
  291.         ' An unexpected error occurred--
  292.         ' notify the user and close the connection
  293.         suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
  294.  
  295.         tntConnectTo.Action = CLOSECOMM
  296.     End If
  297. End Sub
  298.  
  299. Sub tntConnectFrom_Recv (RecvData As String)
  300.     If RecvData = "" Then
  301.         ' The connection was closed
  302.         cmdConnect.Enabled = True
  303.         cmdConnectFromClose.Enabled = False
  304.         suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
  305.     Else
  306.         txtConnectFrom.Text = txtConnectFrom.Text + RecvData
  307.         txtConnectFrom.SelStart = Len(txtConnectFrom.Text)
  308.     End If
  309. End Sub
  310.  
  311. Sub tntConnectTo_Cmd (Cmd As Integer, TelnetOption As Integer, SubOption As String)
  312.     ' Which command is it?
  313.     Select Case Cmd
  314.     Case DO_CMD
  315.         If TelnetOption = TERMINAL_TYPE Then
  316.             ' We will support this option
  317.             tntConnectTo.WillOption = TERMINAL_TYPE
  318.         Else
  319.             ' We don't support any others
  320.             tntConnectTo.WontOption = TelnetOption
  321.         End If
  322.  
  323.     Case DONT_CMD
  324.         ' We must agree for a DON'T
  325.         tntConnectTo.WontOption = TelnetOption
  326.  
  327.     Case SB_CMD
  328.         ' We support the TTY terminal type
  329.         If TelnetOption = TERMINAL_TYPE Then
  330.             tntConnectTo.SubOption = Chr$(0) & "tty"
  331.             tntConnectTo.DoSubOption = TERMINAL_TYPE
  332.         End If
  333.  
  334.     Case WILL_CMD
  335.         If TelnetOption = SUPPRESS_GO_AHEAD Then
  336.             ' We will support this option
  337.             tntConnectTo.DoOption = SUPPRESS_GO_AHEAD
  338.         Else
  339.             ' We don't support any others
  340.             tntConnectTo.DontOption = TelnetOption
  341.         End If
  342.  
  343.     Case WONT_CMD
  344.         ' We must agree for a WON'T
  345.         ' tntConnectTo.DontOption = TelnetOption
  346.     End Select
  347. End Sub
  348.  
  349. Sub tntConnectTo_Connect ()
  350.     ' Make the Connect button disabled,
  351.     ' and the Close button enabled.
  352.     cmdConnect.Enabled = False
  353.     cmdConnectToClose.Enabled = True
  354.  
  355.     ' We do not want to support echoing
  356.     tntConnectTo.DontOption = ECHO
  357. End Sub
  358.  
  359. Sub tntConnectTo_Exception (ErrorCode As Integer, ErrorDesc As String)
  360.     ' An unexpected error occurred--
  361.     ' notify the user and close the connection
  362.     suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
  363. End Sub
  364.  
  365. Sub tntConnectTo_Recv (RecvData As String)
  366.     If RecvData = "" Then
  367.         ' The connection was closed
  368.         cmdConnect.Enabled = True
  369.         cmdConnectToClose.Enabled = False
  370.         
  371.         suc% = MessageBox(Me.hWnd, "The connection was closed.", App.Title, 0)
  372.     Else
  373.         txtConnectTo.Text = txtConnectTo.Text + RecvData
  374.         txtConnectTo.SelStart = Len(txtConnectTo.Text)
  375.     End If
  376. End Sub
  377.  
  378. Sub tntListen_Accept (NewSession As Long)
  379.     ' We must pass the connection on to tntConnectFrom
  380.     tntConnectFrom.Session = NewSession
  381. End Sub
  382.  
  383. Sub tntListen_Exception (ErrorCode As Integer, ErrorDesc As String)
  384.     ' An unexpected error occurred--
  385.     ' notify the user and close the connection
  386.     suc% = MessageBox(Me.hWnd, ErrorDesc, App.Title, 0)
  387. End Sub
  388.  
  389. Sub tntListen_Listen ()
  390.     ' Make the Listen button disabled,
  391.     ' and the Stop button enabled.
  392.     cmdListen.Enabled = False
  393.     cmdStop.Enabled = True
  394. End Sub
  395.  
  396. Sub tntListen_Recv (RecvData As String)
  397.     ' The connection was closed
  398.     cmdListen.Enabled = True
  399.     cmdStop.Enabled = False
  400.  
  401.     suc% = MessageBox(Me.hWnd, "Listening was stopped.", App.Title, 0)
  402. End Sub
  403.  
  404. Sub txtConnectFrom_KeyPress (KeyAscii As Integer)
  405.     ' Send the character to the other end
  406.     ' of the connection.
  407.     tntConnectFrom.Send = Chr(KeyAscii)
  408.     
  409.     ' Make sure the character appears at
  410.     ' the end of the text box
  411.     txtConnectFrom.SelStart = Len(txtConnectFrom.Text)
  412. End Sub
  413.  
  414. Sub txtConnectTo_KeyPress (KeyAscii As Integer)
  415.     ' Send the character to the other end
  416.     ' of the connection.
  417.     tntConnectTo.Send = Chr(KeyAscii)
  418.  
  419.     ' Note: carriage returns, went sent, should be followed
  420.     ' by the linefeed character, according to the TELNET
  421.     ' protocol
  422.     If KeyAscii = 13 Then tntConnectTo.Send = Chr$(10)
  423.  
  424.     ' Make sure the character appears at
  425.     ' the end of the text box
  426.     txtConnectTo.SelStart = Len(txtConnectTo.Text)
  427. End Sub
  428.  
  429.